package com.lzb.newloan.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.lzb.newloan.LoanDetailActivity;
import com.lzb.newloan.R;
import com.lzb.newloan.pojo.BorrowPersonPojo;

import java.util.ArrayList;

public class WaitLoanAdapter extends BaseAdapter {

	private ArrayList<BorrowPersonPojo> pojo;
	private LayoutInflater mInflater;
	private Context context;
	private int flag;

	public WaitLoanAdapter(Context context, ArrayList<BorrowPersonPojo> pojo,int flag) {
		this.pojo = pojo;
		this.mInflater = LayoutInflater.from(context);
		this.context = context;
		this.flag = flag;
	}

	public ArrayList<BorrowPersonPojo> getArrayList() {
		return pojo;
	}

	public void setArrayList(ArrayList<BorrowPersonPojo> arrayList) {
		this.pojo = arrayList;
	}

	@Override
	public int getCount() {
		if (pojo == null) {
			return 0;
		} else {
			return pojo.size();
		}
	}

	@Override
	public Object getItem(int arg0) {

		return pojo.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int postition, View convertView, ViewGroup arg2) {
		ViewHoler viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHoler();
			convertView = mInflater.inflate(R.layout.adapter_wait_loan, null);
			viewHolder.date = (TextView) convertView
					.findViewById(R.id.date);
			viewHolder.person = (TextView) convertView.findViewById(R.id.person);
			viewHolder.lx = (TextView) convertView
					.findViewById(R.id.lx);
			viewHolder.money = (TextView) convertView.findViewById(R.id.money);
			viewHolder.jk_time = (TextView) convertView.findViewById(R.id.jk_time);
			viewHolder.fk_time = (TextView) convertView
					.findViewById(R.id.hk_times);
			viewHolder.state = (TextView) convertView.findViewById(R.id.state);
//			viewHolder.hk_txt = (TextView) convertView.findViewById(R.id.hk_txt);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHoler) convertView.getTag();
		}
		final BorrowPersonPojo data = pojo.get(postition);
		viewHolder.person.setText("借款人："+data.getUsername());
		viewHolder.lx.setText("利息："+data.getLx());
		viewHolder.money.setText("金额："+data.getSp_money());
		
		if (data.getTime().equals("empty")) {//还款时间
			viewHolder.fk_time.setVisibility(View.INVISIBLE);
//			viewHolder.hk_txt.setVisibility(View.INVISIBLE);
			viewHolder.date.setVisibility(View.INVISIBLE);
		}else {
			viewHolder.fk_time.setText("还款日期：" +data.getTime());
//			viewHolder.hk_txt.setText("还款日期：" + data.getTime());
			viewHolder.date.setText("还款日期：" + data.getTime());
		}
		
		viewHolder.jk_time.setText("借款日期："+data.getFkTime());
		if (flag==1) {
			viewHolder.state.setText("还款状态："+"放款中");
		}else if(flag==2){
			viewHolder.state.setText("还款状态："+"待还款");
		}else if(flag==3){
			viewHolder.state.setText("还款状态："+"已还款");
		}else {
			viewHolder.state.setText("还款状态："+"已逾期");
//			viewHolder.overdue_cuishou.setVisibility(View.VISIBLE);
//			viewHolder.overdue_txt.setVisibility(View.VISIBLE);
		}
		convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, LoanDetailActivity.class);
				intent.putExtra("jkid", data.getId());
				intent.putExtra("spdz", data.getSpdz());
				intent.putExtra("type", flag);
				context.startActivity(intent);
			}
		});
		return convertView;
	}

	public class ViewHoler {
		private TextView more;
		private TextView hk_txt;
		public TextView date,person, money, lx, jk_time,fk_time,state,overdue_txt,overdue_cuishou;
	}

}
